<?php
/* 
* [***********************]
* @author: mazhenyu[houdunwangmzy@163.com]
* @Date:   2014-06-25 21:21:45
* @Last Modified time: 2014-07-01 23:18:33
*/
class Resume5Model extends Model{
	//指定表名
	public $table = "people_resume5";

	//定义规则
    public $validate = array(
        array("starttime", "regexp:/^\d{4}-\d{1,2}-\d{1,2}$/", "开始时间格式不正确", 2, 3),
        array("endtime", "regexp:/^\d{4}-\d{1,2}-\d{1,2}$/", "结束时间格式不正确", 2, 3),
        array("companyname", "nonull", "企业名称不能为空", 2, 3),
        array("companyname", "maxlen:30", "企业名称不得超过30字", 2, 3),
        array("companyinfo", "maxlen:255", "企业介绍不得超过255字", 3, 3),
        array("job", "nonull", "职务名称不能为空", 2, 3),
        array("job", "maxlen:15", "职务名称不得超于15字", 2, 3),
        array("outstanding", "maxlen:300", "业绩和表现不得超于300字", 3, 3),
    );

    //自动完成
    public $auto = array(
        array("resume1_reid", "_reid", "method", 2, 3)
    );

     /**
     * [_reid 自动完成-处理resume1_reid值]
     * @return [int] [返回post提交过来的数据]
     */
    public function _reid(){
        return Q('post.reid', '', 'intval');
    }


	public function get_data($reid){
		return $this->where(array('resume1_reid'=>$reid))->all();
	}


	 /**
     * [add_data 执行添加动作，需要判断是否超过6条]
     * @param [type] $reReid [与第一阶段关联字段]
     */
    public function add_data($reReid){
        //如果大于6条返回假，否则添加，返回真
        if($this->where(array('resume1_reid'=>$reReid))->count('reid5') > 5){
            return false;
        }
        $this->add();
        //增加每步完成状态
        K('Resume1')->add_step($reReid, 5);
        return true;
    }

     /**
     * [get_id_data 通过主键id获得单条经历]
     * @param  [type] $reid5 [主键id]
     * @return [type]        [description]
     */
    public function get_id_data($reid5){
        return $this->find($reid5);
    }

        /**
     * [del_data 通过主键id删除，还需要$reid,保证用户不会通过改变get参数乱删]
     * @param  [int] $reid4   [当前表主键id]
     * @return [type]        [description]
     */
    public function del_data($reid5, $reReid){
        // where条件
        $where = array(
            'reid5'         => $reid5,
            'resume1_reid'  => $reReid
            );
        $this->where($where)->delete();
        //如果工作经历全部被删除，则当前步骤也就是第5步为没有完成
        if($this->where(array('resume1_reid'  => $reReid))->count() == 0){
            //执行删除步骤
            K('Resume1')->minus_step($reReid, 5);
        }
    }

    public function update_data($reid5, $reid)
    {
         // where条件
        $where = array(
            'reid5'         => $reid5,
            'resume1_reid'  => $reid
            );

        return $this->where($where)->save();
    }
}
?>
